<template>
  <div>
    <el-row>
      <el-col :span="20" class="flex-start">
        <el-input
          size="small"
          style="width: 300px"
          class="m-l-10"
          v-model="search.carNo"
          placeholder="请输入搜索关键字"
          @change="queryCarNo"
        />
      </el-col>
      <el-col span="4" class="flex-end">
        <!--        filling-storage-car:add-->
        <el-button size="small" type="primary" @click="addNew"
          >新增车辆</el-button
        >
      </el-col>
    </el-row>
    <el-table
      class="m-t-20 my-table"
      :data="data"
      v-loading="loading"
      style="width: 100%"
      border
    >
      <el-table-column type="index" align="center" label="序号" width="60" />
      <el-table-column prop="carNo" label="车牌号" width="100" align="center" />
      <el-table-column
        prop="address"
        label="常驻位置"
        min-width="170"
        align="center"
      />
      <el-table-column fixed="right" label="操作" align="center" width="475">
        <template v-slot="scope">
          <!--            filling-storage-car:delet-->
          <el-button
            @click="deleteRow(scope.row)"
            type="text"
            size="small"
            :loading="removeLoading"
            icon="el-icon-close"
            >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <app-pagination
      ref="paginationRef"
      :total="total"
      class="m-t-20"
      @change="query"
    />
  </div>
</template>

<script>
import {
  confirmWarning,
  getRecords,
  getTotal,
  isNull,
  msgSuccess,
} from "@/util/common-util";
import AppPagination from "@/components/business/app-pagination";
import { getPage, remove } from "@/api/business/filling-storage-car";
import AuthWrapper from "@/components/business/auth-wrapper";

export default {
  name: "rehydration-vehicle-list",
  components: {
    AuthWrapper,
    AppPagination,
  },
  data() {
    return {
      showChangedHistoryFlag: false,
      createTicketFlag: false,
      data: [],
      removeLoading: false,
      loading: false,
      search: {},
      total: 0,
      currRow: {},
    };
  },
  mounted() {
    this.query();
  },
  methods: {
    queryCarNo() {
      this.query();
    },
    query(_page) {
      if (isNull(_page)) {
        _page = this.$refs.paginationRef.getPage();
      }
      console.log(_page);
      this.loading = true;
      getPage(_page, this.search)
        .then((res) => {
          this.data = getRecords(res);
          this.total = getTotal(res);
          this.loading = false;
        })
        .then(() => {
          this.loading = false;
        });
    },
    addNew() {
      this.$emit("add");
    },
    toEdit(_row) {
      this.$emit("edit", _row);
    },
    detail(_row) {
      this.$emit("detail", _row);
    },
    deleteRow(_row) {
      confirmWarning("删除操作", `确定删除车辆吗 ？`, () => {
        this.removeLoading = true;
        remove(_row.id)
          .then((res) => {
            this.removeLoading = false;
            this.query();
            msgSuccess();
          })
          .catch(() => {
            this.removeLoading = false;
          });
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.my-table {
  ::v-deep .el-button--small {
    padding: 0 5px !important;
    font-size: 14px !important;
  }

  ::v-deep td {
    padding: 8px 0 !important;
  }

  ::v-deep .el-button--mini {
    font-size: 12px !important;
    padding: 4px 10px !important;
  }

  ::v-deep .el-button--small {
    padding: 0 5px !important;
    font-size: 14px !important;
  }
}
</style>
